var btnUploadText = '上传';
$(document).ready(function () {
      $("#uploadButton").text(btnUploadText)
      $(".imageShow").hide()
      $('#uploadButton').click(function () {
        $('#imagePic').click();
      });
      $("#imagePic").on("change", function (e) {
        var file = e.target.files[0]; //获取图片资源
        var fileTypes = ["bmp", "jpg", "png", "jpeg"];
        var bTypeMatch = false
        for (var i = 0; i < fileTypes.length; i++) {
          var start = file.name.lastIndexOf(".");
          var fileType = file.name.substring(start + 1);
          if (fileType.toLowerCase() == fileTypes[i]) {
            bTypeMatch = true;
            break;
          }
        }
        if (bTypeMatch) {
          if (file.size <= 1024 * 1024 * 10) {
            var reader = new FileReader();
            reader.readAsDataURL(file); // 读取文件
            // 渲染文件
            reader.onload = function (arg) {
              $(".imageShow").show()
              $("#uploadImageShow").attr("src", arg.target.result)
              btnUploadText = '重新上传'
              $("#uploadButton").text(btnUploadText)
            }
          } else {
            alert('仅支持不超过10M的图片');
            emptyImageUpload("#imagePic")
            $("#uploadImageShow").attr("src", "")
            $(".imageShow").hide()
            btnUploadText = '上传'
            $("#uploadButton").text(btnUploadText)
            return false;
          }
        } else {
          alert('仅限bmp，jpg，png，jpeg图片格式');
          emptyImageUpload("#imagePic")
          $("#uploadImageShow").attr("src", "")
          $(".imageShow").hide()
          btnUploadText = '上传'
          $("#uploadButton").text(btnUploadText)
          return false;
        }
      });
    })
    //清空上传图片信息
    function emptyImageUpload(selector) {
      var fi;
      var sourceParent;
      if (selector) {
        fi = $(selector);
        sourceParent = fi.parent();
      } else {
        return;
      }
      $("<form id='tempImgForm'></form>").appendTo(document.body);
   
      var tempImgForm = $("#tempImgForm");
      tempImgForm.append(fi);
      tempImgForm.get(0).reset();
      sourceParent.append(fi);
      tempImgForm.remove();
}